package com.zzyl.nursing.service.impl;

import java.util.List;

import cn.hutool.core.util.ObjectUtil;
import com.zzyl.common.utils.DateUtils;
import com.zzyl.nursing.dto.NursingTaskIdDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zzyl.nursing.mapper.NursingTaskMapper;
import com.zzyl.nursing.domain.NursingTask;
import com.zzyl.nursing.service.INursingTaskService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.Arrays;
/**
 * 护理任务Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-09-24
 */
@Service
public class NursingTaskServiceImpl extends ServiceImpl<NursingTaskMapper,NursingTask> implements INursingTaskService
{
    @Autowired
    private NursingTaskMapper nursingTaskMapper;

    /**
     * 查询护理任务
     * 
     * @param id 护理任务主键
     * @return 护理任务
     */
    @Override
    public NursingTask selectNursingTaskById(Long id)
    {
        return getById(id);
    }

    /**
     * 查询护理任务列表
     * 
     * @param nursingTask 护理任务
     * @return 护理任务
     */
    @Override
    public List<NursingTask> selectNursingTaskList(NursingTask nursingTask)
    {
        return nursingTaskMapper.selectNursingTaskList(nursingTask);
    }

    /**
     * 新增护理任务
     * 
     * @param nursingTask 护理任务
     * @return 结果
     */
    @Override
    public int insertNursingTask(NursingTask nursingTask)
    {
        return save(nursingTask)?1:0;
    }

    /**
     * 修改护理任务
     * 
     * @param nursingTask 护理任务
     * @return 结果
     */
    @Override
    public int updateNursingTask(NursingTask nursingTask)
    {
        return updateById(nursingTask)?1:0;
    }

    /**
     * 批量删除护理任务
     * 
     * @param ids 需要删除的护理任务主键
     * @return 结果
     */
    @Override
    public int deleteNursingTaskByIds(Long[] ids)
    {
        return removeByIds(Arrays.asList(ids))?1:0;
    }

    /**
     * 删除护理任务信息
     * 
     * @param id 护理任务主键
     * @return 结果
     */
    @Override
    public int deleteNursingTaskById(Long id)
    {
        return removeById(id)?1:0;
    }


    /**
     * 护理任务改期
     *
     * @param nursingTaskIdDto
     */
    @Override
    public void updateTime(NursingTaskIdDto nursingTaskIdDto) {
        NursingTask task = this.lambdaQuery().eq(NursingTask::getId, nursingTaskIdDto.getTaskId()).one();
        task.setEstimatedServerTime(nursingTaskIdDto.getEstimatedServerTime());
        this.updateNursingTask(task);
    }

    /**
     * 取消任务
     *
     * @param nursingTaskIdDto
     */
    @Override
    public void cancel(NursingTaskIdDto nursingTaskIdDto) {
        NursingTask task = this.lambdaQuery().eq(NursingTask::getId, nursingTaskIdDto.getTaskId()).one();
        if (ObjectUtil.isNotEmpty(nursingTaskIdDto.getReason())){
            task.setCancelReason(nursingTaskIdDto.getReason());
        }
        task.setStatus(3);
        this.updateNursingTask(task);
    }

    /**
     * 执行任务
     *
     * @param nursingTaskIdDto
     */
    @Override
    public void taskDo(NursingTaskIdDto nursingTaskIdDto) {
        NursingTask task = this.lambdaQuery().eq(NursingTask::getId, nursingTaskIdDto.getTaskId()).one();
        task.setRealServerTime(nursingTaskIdDto.getEstimatedServerTime());
        if (ObjectUtil.isNotEmpty(nursingTaskIdDto.getMark())){
            task.setMark(nursingTaskIdDto.getMark());
        }
        task.setTaskImage(nursingTaskIdDto.getTaskImage());
        task.setStatus(2);
        this.updateNursingTask(task);
    }
}
